package util;

public class Validate {
	//Hangul hg = new Hangul();

	public String nullchk(String temp){		
		String a="";
		if(temp == null){
			a="";
		}else if(temp.equals("")){
			a="";
		}else{
			a = temp.trim();
		}
		return a;
	}
		
	public String nullchk2(String temp){		
		String a="";
		if(temp == null){
			a="";
		}else if(temp.equals("")){
			a="";
		}
		return a;
	}
	
	public String nullchkTimestamp(String date){		
		if(date == null){
			date = "0000-00-00 00:00:00.0";
		}else if("".equals(date)){
			date = "0000-00-00 00:00:00.0";
		}		
		return date;
	}
	
	public String nullchkTimestamp2(String date){		
		if(date == null){
			date = "0000-00-00 00:00";
		}else if("".equals(date)){
			date = "0000-00-00 00:00";
		}		
		return date;
	}
	
/**
 * 
 * convert type of telephone number By YeonJong Jeong 2012-12-05. 
 * 
 * @param String <telephone number>
 * @return String 
 */
	
	public String convert_telephone(String tel){
		String val_convert = "";
		
		try{
			
			if(tel.length() == 11){
				val_convert = tel.substring(0,3)+"-"+tel.substring(3, 7)+"-"+tel.substring(7, 11);
			}else if(tel.length() == 10){
				val_convert = tel.substring(0,3)+"-"+tel.substring(3, 6)+"-"+tel.substring(6, 10);
			}
			
		}catch(Exception e){
			e.printStackTrace();
		}
		
		return val_convert;
	}
	
/**
 * 
 * create static null check function.
 * 
 */
	
	public static String nullChk(String object){
		String rtnVal = "";
		
		if(object == null || "".equals(object)){
			object = "";
		}
		
		rtnVal = object;
		
		return rtnVal;
	}
	
/* 2013-06-24 : (jeongyej) : 소수점 한자리수까지만 보여주기 */
	
	public String getFirstRound(String object){
		String sReturn = "";
		if(object == null || "".equals(object)){
			sReturn = "";
		}else{
			sReturn = object.substring(0, object.length()-1);
		}
		return sReturn;
	}
	
}
